package service

import (
	"fmt"
	"project/PersonalBlog/dao/db"
	"project/PersonalBlog/model"
)

//CategoryNameByID ..
var categoryNameByID = make(map[int64]*model.Category)

//GetAllCategoryList ..获取所有分类
func GetAllCategoryList() (categorylist []*model.Category) {
	categorylist = db.GetAllCategor()
	return
}

//GetCategoryNameByID ...
func GetCategoryNameByID(id int64) string {
	if _, ok := categoryNameByID[id]; !ok {
		return ""
	}
	return categoryNameByID[id].CategoryName
}

func init() {
	categorylist := GetAllCategoryList()
	if categorylist != nil {
		for _, v := range categorylist {
			categoryNameByID[v.CategoryID] = v
		}
	} else {
		fmt.Println("分类为空--》")
	}
}
